//
//  MZCompatible.h
//  MZToolkitDemo
//
//  Created by Chris Yang on 2017/2/16.
//  Copyright © 2017年 Chris Yang. All rights reserved.
//

#ifndef MZCompatible_h
#define MZCompatible_h

#import "NSDictionary+MZCompatible.h"
#import "MZCompatibleMisc.h"

/* Safe Object */
#define mzSafeStr(inputStr)         ((YES == [inputStr isKindOfClass:[NSString class]]) ? inputStr : @"")
#define mzSafeArray(inputArray)     ((YES == [inputArray isKindOfClass:[NSArray class]]) ? inputArray : @[])
#define mzSafeDic(inputDic)         ((YES == [inputDic isKindOfClass:[NSDictionary class]]) ? inputDic : @{})
#define mzSafeDecimal(inputNum)     \
((YES == [inputNum isKindOfClass:[NSDecimalNumber class]]) \
&& (NO == isnan(inputNum.doubleValue))  \
? inputNum \
: [NSDecimalNumber decimalNumberWithString:@"0"])

/* Safe Check */
#define mzIsEmptyStr(inputStr)          (0 == inputStr.length)
#define mzIsEmptyArray(inputArray)      (0 == inputArray.count)
#define mzIsEmptyDic(inputDic)          (0 == inputDic.allKeys.count)
#define mzIsZeroDecimal(inputNum)       (nil == inputNum || isnan(inputNum.doubleValue) || 0 == inputNum.doubleValue)

/* Safe Callback */
#define mzSafeCallback(cb, para...) \
do { \
if (nil != cb) { \
cb(para); \
} \
} while(0)

/* Weak Self */
#define mzWeakSelf(weakSelf)    __weak __typeof(&*self) weakSelf = self

#endif /* MZCompatible_h */
